<?php
namespace App\Enum;

use App\Utility\BaseEnum;

/**
 * 德洲扑克牌算法
 *
 * @author Administrator
 *        
 */
class PorkerEnum
{

    protected $porkcards = null;

    const GAME_LEVEL_HJTHS = 10;

    const GAME_LEVEL_THS = 9;

    const GAME_LEVEL_FOURS = 8;

    const GAME_LEVEL_HULU = 7;

    const GAME_LEVEL_TONGH = 6;

    const GAME_LEVEL_SHUN = 5;

    const GAME_LEVEL_SANS = 4;

    const GAME_LEVEL_TWOS = 3;

    const GAME_LEVEL_TWO = 2;

    const GAME_LEVEL_HIGTH = 1;

    const GAME_LEVEL_DEFAUTL = 0;

    // 所有牌型
    const PORKER_LEVEL_NAMES = [
        10 => '皇家同花顺',
        9 => '同花顺',
        8 => '四条',
        7 => '葫芦',
        6 => '同花',
        5 => '顺子',
        4 => '三条',
        3 => '两对',
        2 => '对子',
        1 => '高牌',
        0 => '散牌'
    ];

    /*
     * 所有扑克牌
     * 0x01,0x11,0x21,0x31, //方块A~黑桃A
     * 0x02,0x12,0x22,0x32, //方块2~黑桃2
     * 0x03,0x13,0x23,0x33, //方块3~黑桃3
     * 0x04,0x14,0x24,0x34, //方块4~黑桃4
     * 0x05,0x15,0x25,0x35, //方块5~黑桃5
     * 0x06,0x16,0x26,0x36, //方块6~黑桃6
     * 0x07,0x17,0x27,0x37, //方块7~黑桃7
     * 0x08,0x18,0x28,0x38, //方块8~黑桃8
     * 0x09,0x19,0x29,0x39, //方块9~黑桃9
     * 0x0A,0x1A,0x2A,0x3A, //方块10~黑桃10
     * 0x0B,0x1B,0x2B,0x3B, //方块J~黑桃J
     * 0x0C,0x1C,0x2C,0x3C, //方块Q~黑桃Q
     * 0x0D,0x1D,0x2D,0x3D, //方块K~黑桃K
     */

    // 构造
    function __construct()
    {
        $this->porkcards = CardEnum::CARD_FULL_LIST;
    }

    // 计算点数；
    public static function getPorkerDott($cval = false)
    {
        if ($cval === false) return FALSE;
        $res = $cval & 0x0f;
        if (intval($res) === 1) {
            $res = 14; // A 用14的点做为值计算
        }
        return $res;
    }

    /**
     * TODO 皇家同花顺；
     * 五张：10,J,Q,K,A (各种花色)
     */
    private static function checkIsHuangShun($nums, & $huaInx = FALSE)
    {
        $result = FALSE;
        $tempString = '[[1,10,11,12,13],[17,26,27,28,29],[33,42,43,44,45],[49,58,59,60,61]]';
        $huanxunList = json_decode($tempString, TRUE);
        foreach ($huanxunList as $oneArr) {
            $diffBar = ! empty($oneArr) ? array_diff($nums, $oneArr) : FALSE; // 对比
            if ($diffBar !== FALSE && empty($diffBar)) { // 对比是Empty
                $result = TRUE;
                $huaInx = CardEnum::getCardHua($oneArr[0]); // 花色
                break;
            }
        }
        return $result;
    }
    /**
     * 解析手牌点数
     * @param array $onecards
     * @param array $huaVals
     * @return boolean|boolean[]|number[] 点数
     */
    private static function parseCardDotts($onecards , & $huaVals = FALSE){
        if (!$onecards)return FALSE;
        // 记录牌数据；
        $dottVals = [];
        foreach ($onecards as $carval) {
            $dottVals[$carval] = self::getPorkerDott($carval); // 扑克牌点数；
            $huaVals[$carval] = CardEnum::getCardHua($carval); // 花色
        }
        return $dottVals;
    }
    
    /*参数：c     
     * 为 int 型数组的地址
     start 为排列数组的起始下标
     end   为排列数组的结束下标+1
     */
    public static function publicPaiNums($nums , $offen) {
        $res = array();
        $totalNum = !empty($nums) ? sizeof($nums) : 0 ;  //总数
        if ($offen <= 0 || $offen > $totalNum) {
            return $res;
        }
        // 组合组列表显示
        for ($i = 0 ; $i < $totalNum; $i ++ ) {
            $t = array( $nums[$i] );
            if ($offen == 1) {
                $res[] = $t;
            } else {
                $b = array_slice($nums , $i+1);
                $c = self::publicPaiNums($b, $offen - 1);
                foreach ($c as $v) {
                    $res[] = array_merge($t, $v);
                }
            }
        }
        return $res;
    }

    /**
     * TODO 统计五张牌的总点数
     * @param array $onecards
     * @param number $LevelDottValue 最高牌型的点数值
     */
    public static function parseOneCardDottod($onecards, & $LevelDottValue = 0,& $lastRlevel = FALSE)
    {
        //$onecards=[18,3,4,6,7];
        //$onecards=[01,02,03,4,5];
        $parseRes = [];
        $huaInx = FALSE; // 花色
        $LevelCode = 0; // 牌型值，默认为散牌

        $huaVals = [];
        // 记录牌数据；
        $dottVals = self::parseCardDotts($onecards,$huaVals);
        // 五张牌中的花色数统计
        $huaTongjiNum = ! empty($huaVals) ? sizeof(array_unique($huaVals)) : 0;
        $dottValsCount = array_count_values($dottVals); // 统计点数的数量；
        $maxDottNum = ! empty($dottValsCount) ? max($dottValsCount) : 0; // 点数相同的个数
        
        // TODO 定牌型内容（包含点数，花色）
        $IsHuan = self::checkIsHuangShun($onecards, $huaInx);
        // 皇家同花顺最大（Level定最大 100 --- [10 J Q K A] ）
        if ($IsHuan === TRUE) {
            $LevelCode = self::GAME_LEVEL_HJTHS;
            $LevelDottValue = max($huaVals);
            $lastRlevel = "0XAEA000";
            //var_dump($lastRlevel . "---dot:{$LevelDottValue}, last:{$lastRlevel}===> 16Int :" . $lastRlevel);exit ;
        } else {
            $shunGe = 0;
            $isTempShun = false;
            $LevelDottValue = max($dottVals);                   // 默认最高点数
            if (! empty($dottValsCount) && $maxDottNum === 1) { // 顺子判断用
                $maxshunDot = max(array_keys($dottValsCount));
                
                // 当所有牌都是数字时，把A点数值换成14表示最高点值
                if (!empty($dottValsCount) && array_key_exists(14, $dottValsCount) && ($maxshunDot < 10)) {
                    $dottValsCount[1] = intval($dottValsCount[14]); // 是否为特殊顺子[ 不同花 10JQKA] ；
                    unset($dottValsCount[14]);
                }
                $dottVals2 = array_keys($dottValsCount);
                @sort($dottVals2);
                $isTempShun = (!empty($dottVals2) && implode("-", $dottVals2) == '1-2-3-4-5') ? TRUE : FALSE; // 特殊顺子
                for ($i = 0; $i < 4; $i ++) {
                    $j = $i + 1;    // 顺子每张牌值相差 1
                    if ($dottVals2[$i] + 1 == $dottVals2[$j]) {
                        $shunGe ++;
                    } 
                }
            }
            //print_r($dottValsCount);exit ;
            $countPnum = array_count_values($dottValsCount);
            //var_dump("SHUE GE ==". $shunGe . " Max-Dot-Num: ". $maxDottNum . " count=".print_r($countPnum,true)) ;
            
            // 是否为 [ 顺子 ]
            if ($shunGe === 4 && $maxDottNum === 1) {
                $LevelCode = self::GAME_LEVEL_SHUN;         // 顺子
                $maxDot = max($dottVals);
                $minDot = min($dottVals);   
                if ($isTempShun === true) {
                    $maxDot = 5;                            // 加个特例：A12345为最小的顺子；
                    $minDot = 1; 
                }
                if ($huaTongjiNum === 1) {
                    $LevelCode = self::GAME_LEVEL_THS;      // 同花顺子(只有一种花色)
                    $lastRlevel = '0x9'.dechex($maxDot)  .dechex($minDot).'000';      //同花顺0x9
                }else{
                    $lastRlevel = '0x5'.dechex($maxDot)  .dechex($minDot).'000';      //顺子0x5
                }
                
                //var_dump($lastRlevel . "---dot:{$LevelDottValue}, last:{$lastRlevel}===> 16Int :" . $lastRlevel);exit ;
                
            } else if ($maxDottNum >= 2) {
                if ($maxDottNum === 4) {
                    $LevelCode = self::GAME_LEVEL_FOURS;    // 四条
                    $LevelDottValue = array_search(4, $dottValsCount);
                    $onekey = array_search(1, $dottValsCount);
                    //新牌等级
                    $lastRlevel = '0x8'.dechex($LevelDottValue)  .dechex($onekey) .'000';
                    //var_dump($lastRlevel . "---dot:{$LevelDottValue}, last:{$onekey}===> 16Int :" . $lastRlevel);exit ;
                } else if ($maxDottNum === 3) {
                    $LevelCode = self::GAME_LEVEL_SANS;     // 三条
                    $LevelDottValue = array_search(3, $dottValsCount);
                    if (in_array(2, $dottValsCount, TRUE)) {
                        $LevelCode = self::GAME_LEVEL_HULU;             // 葫芦(比三个牌的点数就可以) $nextLevDott = array_search(2, $dottValsCount); //取两张的值
                        $nextLevDott = array_search(2, $dottValsCount); //取剩余两张的值
                        $lastRlevel = '0x7'.dechex($LevelDottValue)  .dechex($nextLevDott) .'000';
                    }else{
                        unset($dottValsCount[$LevelDottValue]);
                        //组成三条的通值
                        $nextLevDott = self::groupLevelCode($dottValsCount);
                        if($nextLevDott !== FALSE && $nextLevDott != ""){
                            $lastRlevel = '0X4'.dechex($LevelDottValue) . $nextLevDott .'00'; //还有两种其它牌值；
                        }
                    }
                    //var_dump($lastRlevel . "---dot:{$LevelDottValue}, last:{$nextLevDott}===> 16Int :" . $lastRlevel);exit ;
                } 
                //TODO 统计对子的情况
                else if ($maxDottNum == 2 && ! empty($countPnum) && array_key_exists(2, $countPnum) && intval($countPnum[2]) === 2) { 
                    $newDots = [];                      // 取较大的点值；
                    $lastDotVal = false;
                    $LevelCode = self::GAME_LEVEL_TWOS; // 为两对对子
                    foreach ($dottValsCount as $ork => $orv) {
                        if ($orv === 2) { $newDots[] = $ork; }
                        if ($orv === 1) { $lastDotVal = $ork; }
                    }
                    //两对时取点值为最大的那个点；
                    if (!empty($newDots) && $lastDotVal !== FALSE) {
                        $LevelDottValue = max($newDots);
                        $secValue = min($newDots);
                        $lastRlevel = '0x3'.dechex($LevelDottValue).dechex($secValue).dechex($lastDotVal) .'00'; //还有两种其它牌值
                    }
                } else { //一个对子 
                    $LevelCode = self::GAME_LEVEL_TWO;          // 默认 对子
                    $LevelDottValue = array_search(2, $dottValsCount); // 取对子(统计点数为2)的点数；
                    unset($dottValsCount[$LevelDottValue]);
                    $otherkey = self::groupLevelCode($dottValsCount);
                    if($otherkey !== FALSE && $otherkey != ""){
                        $lastRlevel = '0x2'.dechex($LevelDottValue).$otherkey .'0'; //还有两种其它牌值；
                    }
                }
                //var_dump("对子：---dot:{$LevelDottValue}, last:===> 16Int :" . $lastRlevel);exit ;
            } else {
                // 散牌数据：处理内容先不做
                $LevelCode = self::GAME_LEVEL_HIGTH;
                $defUnix = '0X1';
                //判断是否同花；
                if ($huaTongjiNum === 1) {
                    $defUnix = '0X6';
                    $LevelCode = self::GAME_LEVEL_TONGH;        // 同花(只有一种花色)
                }
                $otherkey = self::groupLevelCode($dottValsCount);
                if($otherkey !== FALSE && $otherkey != ""){
                    $lastRlevel = $defUnix.$otherkey;          //五张都排序操作
                }
                //var_dump("散牌：---dot:{$LevelDottValue}, last:===> 16Int :" . $lastRlevel);exit ;
            }
        }
        $parseRes = [
            'level' => $LevelCode,
            "huaIndex" => $huaInx,
            "maxLevelDot" => $LevelDottValue
        ];
        return $parseRes;
    }
    
    //TODO 组装剩余的几位值
    protected static function groupLevelCode($dottVals){
        $lastRlevel = '';                            //转化为从大到小排序
        $allDotKey = !empty($dottVals) ? array_keys($dottVals) : FALSE;        //还有两种其它牌值；
        if(!empty($dottVals) && !empty($allDotKey)) {
            @rsort($allDotKey);
            foreach ($allDotKey as $kvl){
                $lastRlevel .= dechex($kvl);                //10进制转16为string
            }
        }
        return $lastRlevel;
    }

    /**
     * TODO 对比两个牌的大小
     * @param array $onecards  第一手牌
     * @param array $secondcards  第二手牌
     * @param boolean $other
     */
    public static function combCardSize($onecards, $secondcards, $other = FALSE)
    {
        $leveNames = self::PORKER_LEVEL_NAMES;  // 比较大小等级
        $lastRes = [ "winStatus" => -1, "lists" => FALSE ];
        $secondDot1 = $secondDot2 = FALSE;
        
        $cardLevel_1 = $cardLevel_2 = FALSE;
        $oneLevel = self::parseOneCardDottod($onecards,$secondDot1,$cardLevel_1);
        $nextLevel = self::parseOneCardDottod($secondcards,$secondDot2,$cardLevel_2);
        $oneLev = isset($oneLevel['level']) ? intval($oneLevel['level']) : 0;
        $twoLev = isset($nextLevel['level']) ? intval($nextLevel['level']) : 0;
        // TODO 对比两个牌型大小，计算牌型数据
        if (! empty($oneLevel) && ! empty($nextLevel) && $oneLev > 0 && $twoLev > 0) {
            //TODO 对比牌型等级
            $levName1 = isset($leveNames[$oneLev]) ? $leveNames[$oneLev] : "";
            $levName2 = isset($leveNames[$twoLev]) ? $leveNames[$twoLev] : "";
            //TODO 比大小 ====> 使用新的比牌方案
            if (!empty($cardLevel_1) && !empty($cardLevel_2)) {
                //var_dump("16Int:".$cardLevel_1. " ===> chan10data:". hexdec($cardLevel_1)); // print "int(160)" 
                $oneFo = hexdec($cardLevel_1);
                $twoFo = hexdec($cardLevel_2);
                
                //TODO 对比两个值的大小
                $lastRes["winStatus"] = 0;
                if ($oneFo > $twoFo) { // 直接等级高 A > B 赢
                    $lastRes["winStatus"] = 1;
                } else if ($oneLev === $twoLev) {
                    $lastRes["winStatus"] = 100;
                } 
                
                //补全牌值
                $lastRes["lists"] = array(
                    ["level"=>$oneLev,"pLevel"=> $cardLevel_1,"name"=> $levName1,"cards"=> implode(',', $onecards)],
                    ["level"=>$twoLev,"pLevel"=> $cardLevel_2,"name"=> $levName2,"cards"=> implode(',', $secondcards)]
                );
            }
            /* if ($oneLev > $twoLev) { // 直接等级高 A > B 赢

                $lastRes["winStatus"] = 1;
            } else if ($oneLev < $twoLev) {

                $lastRes["winStatus"] = 0;
            } else {
                $lastValue = FALSE;
                // 相等的情况（判断牌型相同时的值，第二层判断节点值，如果还不行就得重新判断）
                if ($secondDot1 > $secondDot2) {
                    $lastValue = 1;
                }else if ($secondDot1 < $secondDot2) {
                    $lastValue = 0;
                }else{
                    echo "两手牌的第二张比较大小:{$secondDot1},{$secondDot2}; 当前等级：{$oneLev}, 牌面：". json_encode([$onecards,$secondcards]) ."<br/> ";
                    $lastValue = self::combCardParseTong($oneLev, $onecards, $secondcards);
                }
                //比完第二手牌还不能决定
                $lastRes["winStatus"] = $lastValue;
            } */
        }
        return $lastRes;
    }

    
    
    /**
     * TODO 取手牌中的最大牌型数据（排列组合）
     */
    public static function getPlayMaxCards($cards,$selectNum = 5 , & $maxSelCardLevel = FALSE){
        $leveNames = self::PORKER_LEVEL_NAMES;  // 比较大小等级
        $maxSelCard = FALSE;
        //最大值 ===> 取最大牌型的值； 
        $allList = self::publicPaiNums($cards, $selectNum);
        if(!empty($allList)){
            foreach ($allList as $onecard ){
                $cardLev = $secoo = FALSE;
                //echo "<br>".json_encode($onecard);
                if (!$maxSelCard) {  
                    $maxSelCard = $onecard; 
                    $tempres = self::parseOneCardDottod($onecard,$secoo,$cardLev);
                    $tempIndex = isset($tempres['level']) ? intval($tempres['level']) : 1;
                    $levName1 = isset($leveNames[$tempIndex]) ? $leveNames[$tempIndex] : "";
                    $maxSelCardLevel = ["level"=>$tempIndex ,"pLevel"=> $cardLev,"name"=> $levName1,"cards"=> implode(',', $onecard)] ;
                }else{
                    //有第一手牌之后就直接用当前手牌跟前面手牌相比；
                    $gathRes = self::combCardSize($onecard,$maxSelCard);
                    $gathList = isset($gathRes["lists"]) ? $gathRes["lists"] : FALSE ;
                    if (isset($gathRes['winStatus']) && intval($gathRes['winStatus']) === 1) {  //前面手牌赢了后面的牌，把最大的手牌换掉
                        $maxSelCard = $onecard;
                        $maxSelCardLevel = isset($gathList) ? reset($gathList): FALSE;          //大的在前面
                    }
                }
                
            }
        }
        //取出牌数据；
        //echo "取出选择的牌：" . print_r([$maxSelCard,$maxSelCardLevel],true);
        return $maxSelCard;
    }
    
    
    
    //TODO 玩家的手牌数据比大小(要从大到小排序下来，相等的情况用同值表示)
    public static function playCombSize($players = FALSE,&$pLevelCount = FALSE,&$maxPlevInfo = FALSE){
        $sizeWei = [];
        
        $cardsWei = [];
        $lastNum = !empty($players) ? sizeof($players) :0;
        $playeList = !empty($players) ? array_values($players) :0;
        if( $lastNum >= 2 && !empty($playeList)){
            //TODO 冒泡排序
            for($st = 0; $st < $lastNum ; $st ++ ){
                for($yt = $st + 1; $yt < $lastNum ; $yt ++ ){
                    $secValue = $playeList[$yt] ?? 0;
                    $firstValue = $playeList[$st] ?? 0;  //这个值是变化着的就得实时拿和实时取值
                    $seat1 = $firstValue['seatNo'] ?? -1;
                    $seat2 = $secValue['seatNo'] ?? -1;
                    
                    if (!empty($firstValue) && !empty($secValue) && isset($firstValue['maxCards']) && isset($secValue['maxCards'])) {
                        $cards = !empty($firstValue['maxCards']) ? explode(',', $firstValue['maxCards']) : FALSE;
                        $seccard = !empty($secValue['maxCards']) ? explode(',', $secValue['maxCards']) : FALSE;
                        if(!empty($cards) && !empty($seccard) && $seat1 != $seat2 && $seat1 >= 0){
                            //TODO 有第一手牌之后就直接用当前手牌跟前面手牌相比；
                            $gathRes = self::combCardSize($cards,$seccard);
                            $winSta = isset($gathRes['winStatus']) ?  intval($gathRes['winStatus']) : -1;
                            //echo "比牌：seat($seat1--$seat2) --> win_code : $winSta <br/>";
                            if(!empty($gathRes) && $winSta >= 0){
                                $cardsWei[$seat1]=$gathRes['lists'][0];
                                $cardsWei[$seat2]=$gathRes['lists'][1];
                                //TODO 从大到小的顺序牌列（把小值往后移,winStatus = 1或100，前位大于后位，数据不动，= 0 时才修改）
                                if ($winSta  === 0) {
                                    $temp = $playeList[$st];
                                    $playeList[$st] = $playeList[$yt];      //把大的值放前面去
                                    $playeList[$yt] = $temp;                //把小的值放后面去
                                }
                            }
                        }
                    }
                }
            }
            
            //TODO 整理最大值（计算最大值是否有多个）
            $levelList = array_column($playeList, "pLevel","seatNo");
            $maxPlev = max($levelList);                     //取最大的那个值
            $pLevelCount = array_count_values($levelList);
            $maxPlevNum = $pLevelCount[$maxPlev] ?? 0;      //最大值的个数统计
            $maxPlevInfo = ["pLevel"=> $maxPlev,"num" =>$maxPlevNum ];
        }
        return $playeList;
    }
    
    
    
    
    /**
     * TODO 比较相同牌型的牌的大小
     * @param int $oneLev
     * @param array $onecards
     * @param array $secondcards
     */
    protected static function combCardParseTong($oneLev, $onecards, $secondcards)
    {
        $defaultWin = -1; //默认第一位赢；
        //比牌数据
        $dottVals1 = self::parseCardDotts($onecards);
        $dottVals2 = self::parseCardDotts($secondcards);
        if(!$dottVals2 || !$dottVals1) return FALSE;
        
        @rsort($dottVals1); //倒序牌
        @rsort($dottVals2);
        
        $dottCount1 = array_count_values($dottVals1);
        $dottCount2 = array_count_values($dottVals2);
        
        //TODO 高牌判断第三大牌开始；
        if ($oneLev === self::GAME_LEVEL_HIGTH) {
            
            $defaultWin = self::thanWhoLarge($dottVals1, $dottVals2);     // 高牌只比层级比大小
        }
        //TODO 比牌对子（两对时，比第二对谁大）
        else if ($oneLev === self::GAME_LEVEL_TWOS ) { 
            $defaultWin = 1;
            $onet = $twot = FALSE;
            $lastVal1 = self::getDuiTwoVal($dottCount1,$onet);  //取最小对；
            $lastVal2 = self::getDuiTwoVal($dottCount2,$twot);  //取最小对；
            
            //取最小对比较
            if ($lastVal1 > 0 && $lastVal2 >0 && $lastVal2 < $lastVal1) {
                $defaultWin = 0;
            }else if($lastVal1 > 0 && $lastVal2 >0 && $lastVal2 === $lastVal1){
                //第二对点数相同比第最后一张牌
                if(!empty($onet) && !empty($twot) && isset($onet[0]) && isset($twot[0])  && intval($onet[0]) < intval($twot[0])){
                    $defaultWin = 0;    // 比输情况
                }else if(!empty($onet) && !empty($twot) && isset($onet[0]) && isset($twot[0])  && intval($onet[0]) === intval($twot[0])){
                    
                    $defaultWin = 100;  //都比完点数时再比相等的情况；
                }
            }
        }
        //TODO 只是对子（对子相同时，比其它三张牌谁大）
        else if ($oneLev === self::GAME_LEVEL_TWO ) {
            $onet = $twot = FALSE;
            self::getDuiTwoVal($dottCount1,$onet);
            self::getDuiTwoVal($dottCount2,$twot);
            //比第最后一张牌
            if(!empty($onet) && !empty($twot) && sizeof($onet) == 3){
                $defaultWin = self::thanWhoLarge($onet, $twot);     // 层级比大小
            }
        }
        //TODO 只是同花（同花色最大点数相同时取，比其它四张牌谁大）
        else if ($oneLev === self::GAME_LEVEL_TONGH ){
            $defaultWin = self::thanWhoLarge($dottVals1, $dottVals2);     // 层级比大小(直接比点数大小)
        }
        
        return $defaultWin;
    }
    
    /**
     * TODO 一层一层比大小
     * @param array $dottVals1  第一值
     * @param array $dottVals2  第二值
     * @return boolean|number
     */
    private static function thanWhoLarge($dottVals1,$dottVals2) {
        $defaultWin = 1; //默认是前面的大
        if(!$dottVals1 || !$dottVals2 ) return FALSE;
        
        $tatalWei = sizeof($dottVals1);
        for ($i = 0; $i < $tatalWei; $i++) {
            if (isset($dottVals1[$i]) && isset($dottVals2[$i]) && intval($dottVals1[$i]) == intval($dottVals2[$i]) ) {  //只比相同位
                if($i + 1 == $tatalWei){  //比到最后一位还想同，就是牌型相等
                    $defaultWin = 100; 
                    break;
                }else{
                    continue;
                }
            }else if(intval($dottVals1[$i]) < intval($dottVals2[$i])){ //A玩家的第N位，小于B玩家的第N位 就表示 B赢了这局；
                $defaultWin = 0;
                break;
            }else if(intval($dottVals1[$i]) > intval($dottVals2[$i])){ //A玩家的第N位，小于B玩家的第N位 就表示 B赢了这局；
                $defaultWin = 1;
                break;
            }
        }
        return $defaultWin;
    }
    
    
    /**
     * TODO 取两对中的第二大对子值
     * @param array $dottCountList
     * @param array $lastarr
     * @return boolean|mixed
     */
    private static function getDuiTwoVal($dottCountList,&$lastarr = []) {
        $sel_twoarr = [];
        foreach ($dottCountList as $o1 =>$pval){
            if ($pval === 1) { $lastarr [] = $o1; }
            if ($pval === 2) { $sel_twoarr [] = $o1; }
        }
        $lastMinval = !empty($sel_twoarr) ? min($sel_twoarr) : FALSE;
        
        return $lastMinval;
    }
}
